package tree;

import java.util.LinkedList;
import java.util.Queue;

class TreeNode {
    int val = 0;
    TreeNode left = null;
    TreeNode right = null;
    public TreeNode(int val) {
      this.val = val;
    }
  }
public class test {
    public boolean isCompleteTree (TreeNode root) {
        // write code here
        Queue<TreeNode> queue = new LinkedList<>();
        queue.offer(root);
        while(queue != null){
            int size = queue.size();
            while(size-- > 0){
                if(root.left != null){
                    queue.offer(root.left);
                }
                if(root.right != null){
                    queue.offer(root.right);
                }
                queue.poll();
            }
        }
        while(queue != null){
            TreeNode tmp = queue.peek();
            if(tmp == null){
                return false;
            }
            queue.poll();
        }
        return true;
    }
    public static void main(String[] args) {

    }
}
